<template>
    <view class="home">
        <view class="consult">
            <!-- <view class="serviceconsultation">服务咨询</view> -->
            <view class="clickconsult">
                <image :src="imgsrc" mode="widthFix"></image>
            </view>
            <view class="FormSubmission">
                <view class="formname">
                    <text class="formtext">姓名</text><input type="text" v-model="userInfo.name" style="font-size: 26rpx;">
                </view>
                <view class="formname">
                    <view class="formtext">联系方式</view><input type="text" v-model="userInfo.phone" :maxlength="11" style="font-size: 26rpx;"
                        @input="inputValue2" />
                </view>
                <view class="formname formarea">
                    <view class="formtext">问题描述</view><textarea cols="100" row="5" v-model="userInfo.intro" style="font-size: 26rpx;padding: 15rpx;box-sizing: border-box;"></textarea>
                </view>
            </view>
            <view class="consult-btn" @click="gosubmit()">提交</view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                loading: true,
                userInfo: {
                    name: '',
                    tel: '',
                    intro: '',
                    admin_id: '',
                },
                imgsrc: '',
                imgsrc0: '',
                id: "",
                info: [],
                share_code: '',
                share_title: '',
                shenhe: 0
            }
        },
        onLoad(option) {
            this.id = option.id
            // this.imgsrc = 'https://ms.ys-n.com' + option.imgsrc
            this.imgsrc = 'https://ms.ys-n.com' + option.imgsrc
			this.imgsrc0=option.imgsrc
			let that = this;
            uni.request({
                url: 'https://ms.ys-n.com/api/index/index',
                method: 'POST',
                header: {
                    'Content-Type': 'application/json',
                },
                data: {
                    'id': option.id
                },
                success: res => {
                    that.info = res.data.data;
                    that.userInfo.admin_id = res.data.data.id;
                    that.share_code = res.data.data.share_code;
                    that.share_title = res.data.data.share_title;
                },
                fail: () => {},
                complete: () => {}
            });

            uni.request({
                url: 'https://ms.ys-n.com/api/index/getsite',
                method: 'POST',
                header: {
                    'Content-Type': 'application/json',
                },
                data: {},
                success: res => {
                    console.log(res)
                },
                fail: () => {},
                complete: () => {}
            });

        },
		onShareAppMessage(option) {
			let that = this;
			return {
				title: "沈阳麦穗丨点击在线预约",
				imageUrl: that.imgsrc, // 支持本地或远程图片，默认是小程序 icon
				path: '/pages/submit/submitto?id=' + that.id+'&imgsrc='+that.imgsrc0, // ?后面的参数会在转发页面打开时传入onLoad方法
				// templateId :that.id,
				success() {
					// console.log(that.imgsrc,"图片");
					// console.log('/pages/submit/submitto?id=' + that.id+'&imgsrc='+that.imgsrc0,"当前地址");
					// console.log('转发发布器已调起，并不意味着用户转发成功，微头条不提供这个时机的回调');
				},
				fail() {
					console.log('转发发布器调起失败');
				}
			}
		},
        methods: {
            inputValue2(e) {
                this.userInfo.tel = e.detail.value;
            },
            gosubmit() {
                console.log(this.form);
                if (this.loading == true) {
                    this.loading = false
                    uni.request({
                        url: 'https://ms.ys-n.com/api/index/submit',
                        method: 'POST',
                     	  header: {
                            'Content-Type': 'application/json',
                        },
                        data: this.userInfo,
                        success: res => {
                            this.loading = true
                            if (res.data.code == 0) {
                                this.$u.toast(res.data.msg);
                                return;
                            } else {
                                this.$u.toast(res.data.msg);
                                this.form = {

                                }
                                uni.navigateTo({
                                    url: `/pages/doctor-details/doctor-details?id=${this.id}`
                                })
                                return;
                            }
                            console.log(res);
                        },
                        fail: () => {},
                        complete: () => {}
                    });
                }


            }
        }
    }
</script>

<style lang="scss" scoped>
    // 服务咨询
    .clickconsult {
        width: 100%;

        image {
            width: 100%;
        }
    }

    .consult {
        padding-bottom: 30rpx;

        .consult-btn {
            min-width: 610rpx;
            line-height: 100rpx;
            background-color: #3266EB;
            margin: 120rpx 60rpx 0rpx;
            font-size: 40rpx;
            text-align: center;
            font-weight: 500;
            color: #FFFFFF;
            border-radius: 90rpx;
        }

        .serviceconsultation {
            text-align: center;
            line-height: 110rpx;
            font-size: 36rpx;
            font-family: PingFang SC;
            font-weight: 500;
            color: #252524;
        }

        .FormSubmission {
            // background-color: #3266EB;
            margin: 28rpx 86rpx 0rpx 76rpx;

            .formname {
                display: flex;
                align-items: center;
                justify-content: space-between;
                margin-bottom: 38rpx;
                align-items: stretch;
				line-height: 39px;

                .formtext {
                    display: inline-block;
                    width: 127rpx;
                    text-align: justify;
                    text-align-last: justify;
                    vertical-align: middle;
                    font-size: 26rpx;
                    font-family: PingFang SC;
                    font-weight: 400;
                    color: #252524;
                }

                input {
                    display: inline-block;
                    width: 430rpx;
                    height: 70rpx;
                    border: 1px solid #CBCBCB;
                    background-color: #ffffff;

                }
            }

            .formarea {
                textarea {
                    width: 430rpx;
                    height: 150rpx;
                    border: 1px solid #CBCBCB;
                    background-color: #ffffff;


                }
            }

        }
    }
</style>
